package com.os.opencv.java.chapter7;

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;

public class DistanceTransform {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        //构建一个5*5的小矩阵并导入数据
        Mat src = new Mat(5,5, CvType.CV_8UC1);
        byte[] data = new byte[]{
                1,1,1,1,1,
                1,1,1,1,1,
                1,1,0,1,1,
                1,1,1,1,1,
                1,1,1,1,1
        };
        src.put(0,0,data);

        //在控制台输出矩阵并进行数据确认
        System.out.println("输入矩阵");
        System.out.println(src.dump());
        System.out.println();

        //计算棋盘距离并在控制台输出
        Mat dst = new Mat();
        Imgproc.distanceTransform(src, dst, Imgproc.DIST_C, 3);
        System.out.println("棋盘距离");
        System.out.println(dst.dump());
        System.out.println();

        //计算街区距离并在控制台输出
        Imgproc.distanceTransform(src, dst, Imgproc.DIST_L1, 3);
        System.out.println("街区距离");
        System.out.println(dst.dump());
        System.out.println();

        //计算欧氏距离并在控制台输出
        Imgproc.distanceTransform(src, dst, Imgproc.DIST_L2, 3);
        System.out.println("欧氏距离");
        System.out.println(dst.dump());

        System.out.println();


    }
}
